<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
	<title></title>
</head>
<body>
    <p id="con">abcdefg</p>
</body>
<script type="text/javascript">
	// js面向对象继承的实现
	function Person(name) {
		this.name = name;
	}
	Person.prototype.showName = function() {
		alert(this.name);
	}
	function Worker(name,job) {
		Person.apply(this,arguments)
		this.job = job;
	}
	for(var i in Person.prototype) {
		Worker.prototype = Person.prototype;
	}
	new Worker('easy','coders').showName();

    // 数组去重（原型方法）
    Array.prototype.aaa = function() {
    	this.sort();
    	var res = [this[0]];
    	for(var i=0;i<this.length;i++) {
    		if(this[i] !== res[res.length-1]) {
    			res.push(this[i]);
    		}
    	}
    	return res;
    }

    var arr = "1,a,a,a,b,c,c,d,f,d,1,2,3,3";
    alert(arr.aaa());

    // 获取一堆name名相同的div,点击并显示第几个div
    var box = document.getElementsByTagName('div');
    var index = 0;
    for(var i=0;i<box.length;i++) {
    	box[i].index = i+1;
    	box[i].onclick = function() {
    		alert(this.index);
    	}
    }
    // 第二种
    var box = document.getElementsByTagName('div');
    for(var i=0;i<box.length;i++) {
    	(function(i) {
    		box[i].onclick = function() {
    			alert(i+1);
    		}
    	})(i);
    }

    // 获取字符串里面出现次数最多的元素
    var str = "aasdafsfadadw";
    var obj = {};
    var arr = [];
    var index;
    for(var i=0;i<str.length;i++) {
    	index = str[i];
    	if( !obj[index] ) {
    		obj[index] = 1;
    	}else{
    		obj[index] ++;
    	}
    }
    var Max_key,Max_unm = 0;
    for(key in obj) {
    	if(Max_unm<obj[key]) {
    		Max_key = key;
    	}
    }
    document.write("字母：" Max_key + "次数：" + Max_unm);

    //用js创造一个a标签，在body中显示，点击在新窗口打开
    var a = document.createElment("a");
    a.innerHTML = "百度";
    a.herf = "http://www.baidu.com";
    a.target = "_blank";
    document.body.appendChild(a);

    // 用js截取标签中的abc
    var con = document.getElementById('con');
    var string = con.innerText;
    var result = string.substring(0,3);
    alert(result);
</script>
</html>